home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 5.6 KB | 199 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: BmpFrame.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Henri Lamiraux
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef BMPFRAME_H
- #include "BmpFrame.h"
- #endif
-
- #ifndef BMPFACET_H
- #include "BmpFacet.h"
- #endif
-
- #ifndef BMPPART_H
- #include "BmpPart.h"
- #endif
-
- #ifndef BMPSEL_H
- #include "BmpSel.h"
- #endif
-
- // ----- Graphic Includes -----
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _MENUBAR_
- #include <MenuBar.h>
- #endif
-
- #ifndef _SHAPE_
- #include "Shape.h"
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
- #include <math routines.h>
- #endif
-
- #pragma segment bitmappart
-
- //========================================================================================
- // •• class CBitmapFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // • CBitmapFrame::CBitmapFrame
- //----------------------------------------------------------------------------------------
-
- CBitmapFrame::CBitmapFrame() :
- fBitmapPart(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // • CBitmapFrame::~CBitmapFrame
- //----------------------------------------------------------------------------------------
-
- CBitmapFrame::~CBitmapFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // • CBitmapFrame::InitBitmapFrame
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::InitBitmapFrame(XMPFrame* xmpFrame, CBitmapPart* bitmapPart)
- {
- this->InitFrame(xmpFrame, bitmapPart);
-
- fBitmapPart = bitmapPart;
-
- AddToFocusSet(bitmapPart->GetKeyFocusToken());
- AddToFocusSet(bitmapPart->GetMenuFocusToken());
- AddToFocusSet(bitmapPart->GetSelectionFocusToken());
- }
-
- //----------------------------------------------------------------------------------------
- // • CBitmapFrame::NewFacet
- //----------------------------------------------------------------------------------------
-
- FW_CFacet* CBitmapFrame::NewFacet(XMPFacet* xmpFacet)
- {
- CBitmapFacet* facet = new CBitmapFacet;
- facet->InitBitmapFacet(xmpFacet, fBitmapPart);
-
- return facet;
- }
-
- //----------------------------------------------------------------------------------------
- // • CBitmapFrame::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::DoAdjustMenus(XMPMenuBar* menuBar)
- {
- FW_CFrame::DoAdjustMenus(menuBar);
-
- FW_CPoint ratio = GetZoomRatio();
-
- menuBar->EnableAndCheckCommand(cHalfSize, !IsRoot(), (ratio.x == fl(0.5) && ratio.y == fl(0.5)));
- menuBar->EnableAndCheckCommand(cRealSize, !IsRoot(), (ratio.x == ff(1) && ratio.y == ff(1)));
- menuBar->EnableAndCheckCommand(cDoubleSize, !IsRoot(), (ratio.x == ff(2) && ratio.y == ff(2)));
- }
-
- //----------------------------------------------------------------------------------------
- // • CBitmapFrame::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CBitmapFrame::DoMenuEvent(XMPMenuBar *menuBar, XMPCommandID commandID)
- {
- FW_Boolean result = TRUE;
-
- switch (commandID)
- {
- case cHalfSize:
- case cRealSize:
- case cDoubleSize:
- AdjustBitmapSize(commandID);
- break;
-
- default:
- result = FW_CFrame::DoMenuEvent(menuBar, commandID);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // • CBitmapFrame::AdjustBitmapSize
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::AdjustBitmapSize(XMPCommandID commandID)
- {
- FW_CRect bitmapRect, frameRect;
- fBitmapPart->CalcBitmapRect(&bitmapRect, commandID);
-
- GetFrameShapeBounds(&frameRect);
- frameRect.Place(0, 0);
-
- if (frameRect != bitmapRect)
- {
- XMPShape* oldFrameShape = ::NewXMPShape();
- GetFrameShape(oldFrameShape);
- XMPShape* returnedShape = RequestFrameShape(::NewXMPShape(bitmapRect));
- if (!returnedShape->IsSameAs(oldFrameShape))
- {
- UpdateUsedAndActiveShapes();
- oldFrameShape->Union(returnedShape);
- InvalidateAllFacets(NULL, oldFrameShape);
- }
- delete oldFrameShape;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // • CBitmapFrame::FocusStateChanged
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::FocusStateChanged(XMPTypeToken focus, FW_Boolean newState)
- {
- FW_CFrame::FocusStateChanged(focus, newState);
-
- if (focus == GetPart()->GetSelectionFocusToken())
- {
- CBitmapSelection *bitmapSelection = fBitmapPart->GetBitmapSelection();
- if (!bitmapSelection->IsEmpty())
- bitmapSelection->DrawAnts(this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // • CBitmapFrame::GetZoomRatio
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CBitmapFrame::GetZoomRatio() const
- {
- FW_CRect frameRect;
- GetFrameShapeBounds(&frameRect);
-
- FW_CBitmapShape bitmapShape = fBitmapPart->GetBitmapShape();
- short width, height, rowBytes, pixelSize;
- bitmapShape->GetBitmapInfo(width, height, rowBytes, pixelSize);
-
- FW_CPoint ratio((frameRect.right - frameRect.left) / width,
- (frameRect.bottom - frameRect.top) / height);
-
- return ratio;
- }